package com.magic.gre.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.magic.gre.R;
import com.magic.gre.base.activity.BaseMVPActivity;
import com.magic.gre.helper.Contract;
import com.magic.gre.mvp.contract.RegisterContract;
import com.magic.gre.mvp.presenter.RegisterPresenterImpl;
import com.noname.lib_base_java.util.PathUtil;
import com.noname.lib_base_java.util.ToastUtil;
import com.noname.lib_base_java.util.ValidateUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: Lmoumou
 * Date: 2019-01-10 15:27
 * 文件名: RegisterActivity
 * 描述:
 */
public class RegisterActivity extends BaseMVPActivity<RegisterPresenterImpl> implements RegisterContract.View {
    @BindView(R.id.phone_edt)
    EditText phoneEdt;
    @BindView(R.id.agreement_tv)
    TextView agreementTv;
    @BindView(R.id.agreement_tv2)
    TextView agreementTv2;

    public static void startThis(Context context) {
        Intent intent = new Intent(context.getApplicationContext(), RegisterActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    protected RegisterPresenterImpl creatPresenter() {
        return new RegisterPresenterImpl(this);
    }

    @Override
    protected void netOverride() {

    }


    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        super.initView(savedInstanceState);
    }

    @OnClick(value = {R.id.right_tv, R.id.code_bt,R.id.agreement_tv,R.id.agreement_tv2})
    protected void onClick(View view) {
        switch (view.getId()) {
            case R.id.right_tv:
                LoginActivity.startThis(this);
                break;
            case R.id.code_bt:
                String phoneStr = String.valueOf(phoneEdt.getText());
                if (!ValidateUtil.Mobile(phoneStr)){
                    ToastUtil.getInstance().showNormal(this, "请输入正确的电话号码");
                    return;
                }
                if (!agreementTv.isSelected()){
                    ToastUtil.getInstance().showNormal(this, "您未同意《用户使用协议》");
                    return;
                }
                showLoadDialog();
                mPresenter.pSmsCode(phoneStr,1);
                break;
            case R.id.agreement_tv:
                agreementTv.setSelected(!agreementTv.isSelected());
                break;
            case R.id.agreement_tv2:
                WebActivity.startThis(this,"用户协议", PathUtil.urlPath(Contract.AGREEMENT_URL));
                break;
        }
    }

    @Override
    public void vSmsCode(String code) {
        hideLoadDialog();
        ToastUtil.getInstance().showNormal(this, code);
        CodeActivity.startThis(this, CodeActivity.REGISTER, String.valueOf(phoneEdt.getText()),code);
    }
}
